package com.example.rikao1023.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.Menu
import android.view.MenuInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

abstract class BaseFragment<VDB:ViewDataBinding,VM:ViewModel>(val layout:Int, val vm:VM):Fragment() {

    lateinit var binding:VDB
    lateinit var viewmodel:VM


    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding=DataBindingUtil.inflate(inflater,layout,container,false)
        viewmodel=ViewModelProvider(this).get(vm::class.java)
        initview()
        initdata()

        return binding.root
    }

    abstract fun initdata()
    override fun onDestroy() {
        super.onDestroy()
        binding.unbind()
    }

    abstract fun initview()

}